<?php


class ArticleController extends Controller
{
  /**
   * 查看文章
   * @param int $id
   */
  public function actionView($id = 0)
  {
    $this->checkArticle($id, 0, false);
    ArticleService::instance()->hits($id);
    $token = LearnService::instance()->isLearned($id, Yii::app()->user->id);
    $data = ArticleService::instance()->view($id, true);
    $prev = ArticleService::instance()->prev($id);
    $next = ArticleService::instance()->next($id);
    $this->render('/site/article/view', array(
        'token' => $token,
        'data' => $data,
        'prev' => $prev,
        'next' => $next
    ));
  }

  /**
   * 学习
   * @param int $id
   */
  public function actionLearn($id = 0)
  {
    if(Yii::app()->request->isAjaxRequest){
      echo LearnService::instance()->learn($id, Yii::app()->user->id) === true?1:0;
    }else{
      $this->error('非法请求',400);
    }
  }
} 